#include<bits/stdc++.h>
using namespace std;

int p[1000010],ans=0;
int main()
{
	freopen("detect.in","r",stdin);
	freopen("detect.out","w",stdout);
	int T;
	cin>>T;
	for(int i=1;i<=T;i++)
	{
		int n,m,L,V;
		cin>>n>>m>>L>>V;
		int d,v,a;
		for(int i=1;i<=n;i++)
		{
			cin>>d>>v>>a;
			if(a==0)
			{
				if(v>V)
					ans++;
			}
			else
			{
				if(v>V)
					ans++;
			}
		}
		for(int i=1;i<=n;i++)
			cin>>p[i];
		cout<<ans<<" "<<n-ans+1;
	}
	
	return 0;
}
